package com.leizhi.demo.monitor.controller;

import com.leizhi.demo.monitor.pojo.MediaData;
import com.leizhi.demo.monitor.pojo.WebResult;
import com.leizhi.demo.monitor.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 摄像头控制器
 * @Version 1.0.0-SNAPSHOT
 * @Author leizhi
 * @Date 2025/4/27 12:02
 */
@RestController
@RequestMapping("/monitor")
public class MonitorController {

    @Autowired
    private MonitorService monitorService;


    @GetMapping("/play")
    public WebResult play(String deviceId) {
        if (deviceId == null) return WebResult.error("deviceId 不能为空");
        try {
            MediaData mediaData = monitorService.play(deviceId);
            return WebResult.successWithData(mediaData);
        } catch (RuntimeException e) {
            return WebResult.error(e.getMessage());
        }
    }

    @GetMapping("/bye")
    public WebResult bye(String deviceId) {
        if (deviceId == null) return WebResult.error("deviceId 不能为空");
        try {
            monitorService.bye(deviceId);
            return WebResult.successWithoutData("关闭成功");
        } catch (RuntimeException e) {
            return WebResult.error(e.getMessage());
        }
    }

    @GetMapping("/onCloud")
    public WebResult onCloud(String deviceId) {
        if (deviceId == null) return WebResult.error("deviceId 不能为空");
        try {
            monitorService.onCloud(deviceId);
            return WebResult.successWithoutData("开启成功");
        } catch (RuntimeException e) {
            return WebResult.error(e.getMessage());
        }
    }

    @GetMapping("/offCloud")
    public WebResult offCloud(String deviceId) {
        if (deviceId == null) return WebResult.error("deviceId 不能为空");
        try {
            monitorService.offCloud(deviceId);
            return WebResult.successWithoutData("关闭成功");
        } catch (RuntimeException e) {
            return WebResult.error(e.getMessage());
        }
    }

}
